package com.rovinj_server.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.rovinj_server.R;
import com.rovinj_server.adapter.InventorySkedsubAdapter;
import com.rovinj_server.adapter.TaskSkedsubAdapter;
import com.rovinj_server.db.DBManager;
import com.rovinj_server.entity.InventorySub;
import com.zhy.autolayout.AutoLayoutActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/8.
 */

public class InventorySkedsubActivity extends AutoLayoutActivity {


    @Bind(R.id.relative_layout)
    RelativeLayout mRelativeLayout;
    @Bind(R.id.list_view)
    ListView mListView;
    @Bind(R.id.butt_wu)
    Button mButtWu;
    @Bind(R.id.fh)
    RelativeLayout mFh;
    private List<InventorySub> mListInventory = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_skefsub);
        ButterKnife.bind(this);
        hidStater();
        intiData();
    }

    /**
     * 隐藏状态栏
     */
    private void hidStater() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
    }

    private void intiData() {
        Intent intent = getIntent();
        if (intent != null) {
            int id = (int) intent.getSerializableExtra("id");
            DBManager dbManager = new DBManager(InventorySkedsubActivity.this);
            dbManager.copyDBFile();
            mListInventory = dbManager.findInventoryData(id);
            InventorySkedsubAdapter mAdapter = new InventorySkedsubAdapter(this, mListInventory);
            mListView.setAdapter(mAdapter);
            mAdapter.notifyDataSetChanged();
        }

    }


    @OnClick({R.id.fh, R.id.butt_wu})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fh:
                finish();
                break;
            case R.id.butt_wu:
                Intent intent = new Intent(InventorySkedsubActivity.this, InventoryAllocationActivity.class);
                intent.putExtra("mListInventory", (Serializable) mListInventory);
                startActivity(intent);
                break;
        }
    }
}
